﻿// Bing Maps ASP.NEt Control is a community project available under the Microsoft Public License (Ms-PL)
// Code is provided as is and with no warrenty – Use at your own risk
// View the project and the latest code at http://BingMapsASP.codeplex.com

using System;
using System.ComponentModel;
using System.Reflection;

namespace Microsoft.Live.ServerControls.VE
{
    [AttributeUsage(AttributeTargets.Enum | AttributeTargets.Field)]
    internal class EnumClientNameAttribute : DisplayNameAttribute
    {
        public EnumClientNameAttribute(string displayName)
            : base(displayName)
        {
        }
    }

    internal static class VEHelper
    {
        public static string ToVEEnum(this Enum obj)
        {
            FieldInfo fi = obj.GetType().GetField(obj.ToString());

            foreach (EnumClientNameAttribute attrib in fi.GetCustomAttributes(typeof(EnumClientNameAttribute), true))
            {
                return attrib.DisplayName;
            }
            return string.Empty;
        }
    }
}